<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>browsertestchannel.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_net_browsertestchannel.js.html">browsertestchannel.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2006 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Definition of the BrowserTestChannel class.  A
<a name="line17"></a> * BrowserTestChannel is used during the first part of channel negotiation
<a name="line18"></a> * with the server to create the channel. It helps us determine whether we&#39;re
<a name="line19"></a> * behind a buffering proxy. It also runs the logic to see if the channel
<a name="line20"></a> * has been blocked by a network administrator. This class is part of the
<a name="line21"></a> * BrowserChannel implementation and is not for use by normal application code.
<a name="line22"></a> *
<a name="line23"></a> */
<a name="line24"></a>
<a name="line25"></a>/**
<a name="line26"></a> * Namespace for BrowserChannel
<a name="line27"></a> */
<a name="line28"></a>goog.provide(&#39;goog.net.BrowserTestChannel&#39;);
<a name="line29"></a>
<a name="line30"></a>goog.require(&#39;goog.net.ChannelDebug&#39;);
<a name="line31"></a>goog.require(&#39;goog.net.ChannelRequest&#39;);
<a name="line32"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line33"></a>
<a name="line34"></a>/**
<a name="line35"></a> * Encapsulates the logic for a single BrowserTestChannel.
<a name="line36"></a> *
<a name="line37"></a> * @constructor
<a name="line38"></a> * @param {goog.net.BrowserChannel} channel  The BrowserChannel that owns this
<a name="line39"></a> *     test channel.
<a name="line40"></a> * @param {goog.net.ChannelDebug} channelDebug A ChannelDebug to use for
<a name="line41"></a> *     logging.
<a name="line42"></a> */
<a name="line43"></a>goog.net.BrowserTestChannel = function(channel, channelDebug) {
<a name="line44"></a>  /**
<a name="line45"></a>   * The BrowserChannel that owns this test channel
<a name="line46"></a>   * @type {goog.net.BrowserChannel}
<a name="line47"></a>   * @private
<a name="line48"></a>   */
<a name="line49"></a>  this.channel_ = channel;
<a name="line50"></a>
<a name="line51"></a>  /**
<a name="line52"></a>   * The channel debug to use for logging
<a name="line53"></a>   * @type {goog.net.ChannelDebug}
<a name="line54"></a>   * @private
<a name="line55"></a>   */
<a name="line56"></a>  this.channelDebug_ = channelDebug;
<a name="line57"></a>};
<a name="line58"></a>
<a name="line59"></a>
<a name="line60"></a>/**
<a name="line61"></a> * Extra HTTP headers to add to all the requests sent to the server.
<a name="line62"></a> * @type {Object}
<a name="line63"></a> * @private
<a name="line64"></a> */
<a name="line65"></a>goog.net.BrowserTestChannel.prototype.extraHeaders_ = null;
<a name="line66"></a>
<a name="line67"></a>/**
<a name="line68"></a> * The test request.
<a name="line69"></a> * @type {goog.net.ChannelRequest}
<a name="line70"></a> * @private
<a name="line71"></a> */
<a name="line72"></a>goog.net.BrowserTestChannel.prototype.request_ = null;
<a name="line73"></a>
<a name="line74"></a>/**
<a name="line75"></a> * Whether we have received the first result as an intermediate result. This
<a name="line76"></a> * helps us determine whether we&#39;re behind a buffering proxy.
<a name="line77"></a> * @type {boolean}
<a name="line78"></a> * @private
<a name="line79"></a> */
<a name="line80"></a>goog.net.BrowserTestChannel.prototype.receivedIntermediateResult_ = false;
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * The time for of the first result part. We use timing in IE as a
<a name="line84"></a> * heuristic for whether we&#39;re behind a buffering proxy.
<a name="line85"></a> * @type {number?}
<a name="line86"></a> * @private
<a name="line87"></a> */
<a name="line88"></a>goog.net.BrowserTestChannel.prototype.firstTime_ = null;
<a name="line89"></a>
<a name="line90"></a>/**
<a name="line91"></a> * The time for of the last result part. We use timing in IE as a
<a name="line92"></a> * heuristic for whether we&#39;re behind a buffering proxy.
<a name="line93"></a> * @type {number?}
<a name="line94"></a> * @private
<a name="line95"></a> */
<a name="line96"></a>goog.net.BrowserTestChannel.prototype.lastTime_ = null;
<a name="line97"></a>
<a name="line98"></a>/**
<a name="line99"></a> * The relative path for test requests.
<a name="line100"></a> * @type {string?}
<a name="line101"></a> * @private
<a name="line102"></a> */
<a name="line103"></a>goog.net.BrowserTestChannel.prototype.path_ = null;
<a name="line104"></a>
<a name="line105"></a>/**
<a name="line106"></a> * The state of the state machine for this object.
<a name="line107"></a> *
<a name="line108"></a> * @type {number?}
<a name="line109"></a> * @private
<a name="line110"></a> */
<a name="line111"></a>goog.net.BrowserTestChannel.prototype.state_ = null;
<a name="line112"></a>
<a name="line113"></a>/**
<a name="line114"></a> * The last status code received.
<a name="line115"></a> * @type {number}
<a name="line116"></a> * @private
<a name="line117"></a> */
<a name="line118"></a>goog.net.BrowserTestChannel.prototype.lastStatusCode_ = -1;
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * A subdomain prefix for using a subdomain in IE for the backchannel
<a name="line122"></a> * requests.
<a name="line123"></a> * @type {string?}
<a name="line124"></a> * @private
<a name="line125"></a> */
<a name="line126"></a>goog.net.BrowserTestChannel.prototype.hostPrefix_ = null;
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * A subdomain prefix for testing whether the channel was disabled by
<a name="line130"></a> * a network administrator;
<a name="line131"></a> * @type {string?}
<a name="line132"></a> * @private
<a name="line133"></a> */
<a name="line134"></a>goog.net.BrowserTestChannel.prototype.blockedPrefix_ = null;
<a name="line135"></a>
<a name="line136"></a>
<a name="line137"></a>/**
<a name="line138"></a> * Enum type for the browser test channel state machine
<a name="line139"></a> * @enum {number}
<a name="line140"></a> * @private
<a name="line141"></a> */
<a name="line142"></a>goog.net.BrowserTestChannel.State_ = {
<a name="line143"></a>  /**
<a name="line144"></a>   * The state for the BrowserTestChannel state machine where we making the
<a name="line145"></a>   * initial call to get the server configured parameters.
<a name="line146"></a>   */
<a name="line147"></a>  INIT: 0,
<a name="line148"></a>
<a name="line149"></a>  /**
<a name="line150"></a>   * The state for the BrowserTestChannel state machine where we&#39;re checking to
<a name="line151"></a>   * see if the channel has been blocked.
<a name="line152"></a>   */
<a name="line153"></a>  CHECKING_BLOCKED: 1,
<a name="line154"></a>
<a name="line155"></a>  /**
<a name="line156"></a>   * The  state for the BrowserTestChannel state machine where we&#39;re checking to
<a name="line157"></a>   * se if we&#39;re behind a buffering proxy.
<a name="line158"></a>   */
<a name="line159"></a>  CONNECTION_TESTING: 2
<a name="line160"></a>};
<a name="line161"></a>
<a name="line162"></a>
<a name="line163"></a>/**
<a name="line164"></a> * Time in MS for waiting for the request to see if the channel is blocked.
<a name="line165"></a> * If the response takes longer than this many ms, we assume the request has
<a name="line166"></a> * failed.
<a name="line167"></a> * @type {number}
<a name="line168"></a> * @private
<a name="line169"></a> */
<a name="line170"></a>goog.net.BrowserTestChannel.BLOCKED_TIMEOUT_ = 5000;
<a name="line171"></a>
<a name="line172"></a>/**
<a name="line173"></a> * Number of attempts to try to see if the check to see if we&#39;re blocked
<a name="line174"></a> * succeeds. Sometimes the request can fail because of flaky network conditions
<a name="line175"></a> * and checking multiple times reduces false positives.
<a name="line176"></a> * @type {number}
<a name="line177"></a> * @private
<a name="line178"></a> */
<a name="line179"></a>goog.net.BrowserTestChannel.BLOCKED_RETRIES_ = 3;
<a name="line180"></a>
<a name="line181"></a>/**
<a name="line182"></a> * Time in ms between retries of the blocked request
<a name="line183"></a> * @type {number}
<a name="line184"></a> * @private
<a name="line185"></a> */
<a name="line186"></a>goog.net.BrowserTestChannel.BLOCKED_PAUSE_BETWEEN_RETRIES_ = 2000;
<a name="line187"></a>
<a name="line188"></a>
<a name="line189"></a>/**
<a name="line190"></a> * Sets extra HTTP headers to add to all the requests sent to the server.
<a name="line191"></a> *
<a name="line192"></a> * @param {Object} extraHeaders The HTTP headers.
<a name="line193"></a> */
<a name="line194"></a>goog.net.BrowserTestChannel.prototype.setExtraHeaders = function(extraHeaders) {
<a name="line195"></a>  this.extraHeaders_ = extraHeaders;
<a name="line196"></a>};
<a name="line197"></a>
<a name="line198"></a>
<a name="line199"></a>/**
<a name="line200"></a> * Starts the test channel. This initiates connections to the server.
<a name="line201"></a> *
<a name="line202"></a> * @param {string} path The relative uri for the test connection.
<a name="line203"></a> */
<a name="line204"></a>goog.net.BrowserTestChannel.prototype.connect = function(path) {
<a name="line205"></a>  this.path_ = path;
<a name="line206"></a>  var sendDataUri = this.channel_.getForwardChannelUri(this.path_);
<a name="line207"></a>
<a name="line208"></a>  goog.net.BrowserChannel.notifyStatEvent(
<a name="line209"></a>      goog.net.BrowserChannel.Stat.TEST_STAGE_ONE_START);
<a name="line210"></a>
<a name="line211"></a>  // the first request returns server specific parameters
<a name="line212"></a>  sendDataUri.setParameterValues(&#39;MODE&#39;, &#39;init&#39;);
<a name="line213"></a>  this.request_ = new goog.net.ChannelRequest(this, this.channelDebug_);
<a name="line214"></a>  this.request_.setExtraHeaders(this.extraHeaders_);
<a name="line215"></a>  this.request_.setMaxRetries(0);
<a name="line216"></a>  this.request_.xmlHttpGet(sendDataUri, false, true);
<a name="line217"></a>  this.state_ = goog.net.BrowserTestChannel.State_.INIT;
<a name="line218"></a>};
<a name="line219"></a>
<a name="line220"></a>
<a name="line221"></a>/**
<a name="line222"></a> * Checks to see whether the channel is blocked. This is for implementing the
<a name="line223"></a> * feature that allows network administrators to block Gmail Chat. The
<a name="line224"></a> * strategy to determine if we&#39;re blocked is to try to load an image off a
<a name="line225"></a> * special subdomain that network administrators will block access to if they
<a name="line226"></a> * are trying to block chat. For Gmail Chat, the subdomain is
<a name="line227"></a> * chatenabled.mail.google.com.
<a name="line228"></a> * @private
<a name="line229"></a> */
<a name="line230"></a>goog.net.BrowserTestChannel.prototype.checkBlocked_ = function() {
<a name="line231"></a>  var uri = this.channel_.createDataUri(this.blockedPrefix_,
<a name="line232"></a>      &#39;/mail/images/cleardot.gif&#39;);
<a name="line233"></a>  uri.makeUnique();
<a name="line234"></a>  goog.net.testLoadImageWithRetries(uri.toString(),
<a name="line235"></a>      goog.net.BrowserTestChannel.BLOCKED_TIMEOUT_,
<a name="line236"></a>      goog.bind(this.checkBlockedCallback_, this),
<a name="line237"></a>      goog.net.BrowserTestChannel.BLOCKED_RETRIES_,
<a name="line238"></a>      goog.net.BrowserTestChannel.BLOCKED_PAUSE_BETWEEN_RETRIES_);
<a name="line239"></a>};
<a name="line240"></a>
<a name="line241"></a>
<a name="line242"></a>/**
<a name="line243"></a> * Callback for testLoadImageWithRetries to check if browser channel is
<a name="line244"></a> * blocked.
<a name="line245"></a> * @param {boolean} succeeded Whether the request succeeded.
<a name="line246"></a> * @private
<a name="line247"></a> */
<a name="line248"></a>goog.net.BrowserTestChannel.prototype.checkBlockedCallback_ = function(
<a name="line249"></a>    succeeded) {
<a name="line250"></a>  if (succeeded) {
<a name="line251"></a>    this.state_ = goog.net.BrowserTestChannel.State_.CONNECTION_TESTING;
<a name="line252"></a>    this.connectStage2_();
<a name="line253"></a>  } else {
<a name="line254"></a>    goog.net.BrowserChannel.notifyStatEvent(
<a name="line255"></a>        goog.net.BrowserChannel.Stat.CHANNEL_BLOCKED);
<a name="line256"></a>    this.channel_.testConnectionBlocked(this);
<a name="line257"></a>  }
<a name="line258"></a>};
<a name="line259"></a>
<a name="line260"></a>/**
<a name="line261"></a> * Begins the second stage of the test channel where we test to see if we&#39;re
<a name="line262"></a> * behind a buffering proxy. The server sends back a multi-chunked response
<a name="line263"></a> * with the first chunk containing the content &#39;1&#39; and then two seconds later
<a name="line264"></a> * sending the second chunk containing the content &#39;2&#39;. Depending on how we
<a name="line265"></a> * receive the content, we can tell if we&#39;re behind a buffering proxy.
<a name="line266"></a> * @private
<a name="line267"></a> */
<a name="line268"></a>goog.net.BrowserTestChannel.prototype.connectStage2_ = function() {
<a name="line269"></a>  this.channelDebug_.debug(&#39;TestConnection: starting stage 2&#39;);
<a name="line270"></a>  this.request_ = new goog.net.ChannelRequest(this, this.channelDebug_);
<a name="line271"></a>  this.request_.setExtraHeaders(this.extraHeaders_);
<a name="line272"></a>  this.request_.setMaxRetries(0);
<a name="line273"></a>  var recvDataUri = this.channel_.getBackChannelUri(this.hostPrefix_,
<a name="line274"></a>      /** @type {string} */ (this.path_));
<a name="line275"></a>
<a name="line276"></a>  goog.net.BrowserChannel.notifyStatEvent(
<a name="line277"></a>      goog.net.BrowserChannel.Stat.TEST_STAGE_TWO_START);
<a name="line278"></a>  if (goog.userAgent.IE) {
<a name="line279"></a>    recvDataUri.setParameterValues(&#39;TYPE&#39;, &#39;html&#39;);
<a name="line280"></a>    this.request_.tridentGet(recvDataUri, Boolean(this.hostPrefix_));
<a name="line281"></a>  } else {
<a name="line282"></a>    recvDataUri.setParameterValues(&#39;TYPE&#39;, &#39;xmlhttp&#39;);
<a name="line283"></a>    this.request_.xmlHttpGet(recvDataUri, false);
<a name="line284"></a>  }
<a name="line285"></a>};
<a name="line286"></a>
<a name="line287"></a>
<a name="line288"></a>/**
<a name="line289"></a> * Aborts the test channel.
<a name="line290"></a> */
<a name="line291"></a>goog.net.BrowserTestChannel.prototype.abort = function() {
<a name="line292"></a>  if (this.request_) {
<a name="line293"></a>    this.request_.cancel();
<a name="line294"></a>    this.request_ = null;
<a name="line295"></a>  }
<a name="line296"></a>  this.lastStatusCode_ = -1;
<a name="line297"></a>};
<a name="line298"></a>
<a name="line299"></a>
<a name="line300"></a>/**
<a name="line301"></a> * Returns whether the test channel is closed. The ChannelRequest object expects
<a name="line302"></a> * this method to be implemented on its handler.
<a name="line303"></a> *
<a name="line304"></a> * @return {boolean} Whether the channel is closed.
<a name="line305"></a> */
<a name="line306"></a>goog.net.BrowserTestChannel.prototype.isClosed = function() {
<a name="line307"></a> return false;
<a name="line308"></a>};
<a name="line309"></a>
<a name="line310"></a>
<a name="line311"></a>/**
<a name="line312"></a> * Callback from ChannelRequest for when new data is received
<a name="line313"></a> *
<a name="line314"></a> * @param {goog.net.ChannelRequest} req  The request object.
<a name="line315"></a> * @param {string} responseText The text of the response.
<a name="line316"></a> */
<a name="line317"></a>goog.net.BrowserTestChannel.prototype.onRequestData =
<a name="line318"></a>    function(req, responseText) {
<a name="line319"></a>  this.lastStatusCode_ = req.getLastStatusCode();
<a name="line320"></a>  if (this.state_ == goog.net.BrowserTestChannel.State_.INIT) {
<a name="line321"></a>    this.channelDebug_.debug(&#39;TestConnection: Got data for stage 1&#39;);
<a name="line322"></a>    if (!responseText) {
<a name="line323"></a>      this.channelDebug_.debug(&#39;TestConnection: Null responseText&#39;);
<a name="line324"></a>      // The server should always send text; something is wrong here
<a name="line325"></a>      this.channel_.testConnectionFailure(this,
<a name="line326"></a>          goog.net.ChannelRequest.Error.BAD_DATA);
<a name="line327"></a>      return;
<a name="line328"></a>    }
<a name="line329"></a>    /** @preserveTry */
<a name="line330"></a>    try {
<a name="line331"></a>      var respArray = goog.json.unsafeParse(responseText);
<a name="line332"></a>    } catch (e) {
<a name="line333"></a>      this.channelDebug_.dumpException(e);
<a name="line334"></a>      this.channel_.testConnectionFailure(this,
<a name="line335"></a>          goog.net.ChannelRequest.Error.BAD_DATA);
<a name="line336"></a>      return;
<a name="line337"></a>    }
<a name="line338"></a>    if (this.channel_.getAllowHostPrefix()) {
<a name="line339"></a>      this.hostPrefix_ = respArray[0];
<a name="line340"></a>    } else {
<a name="line341"></a>      this.hostPrefix_ = null;
<a name="line342"></a>    }
<a name="line343"></a>    this.blockedPrefix_ = respArray[1];
<a name="line344"></a>  } else if (this.state_ ==
<a name="line345"></a>             goog.net.BrowserTestChannel.State_.CONNECTION_TESTING) {
<a name="line346"></a>    if (this.receivedIntermediateResult_) {
<a name="line347"></a>      goog.net.BrowserChannel.notifyStatEvent(
<a name="line348"></a>          goog.net.BrowserChannel.Stat.TEST_STAGE_TWO_DATA_TWO);
<a name="line349"></a>      this.lastTime_ = goog.now();
<a name="line350"></a>    } else {
<a name="line351"></a>      // &#39;11111&#39; is used instead of &#39;1&#39; to prevent a small amount of buffering
<a name="line352"></a>      // by Safari.
<a name="line353"></a>      if (responseText == &#39;11111&#39;) {
<a name="line354"></a>        goog.net.BrowserChannel.notifyStatEvent(
<a name="line355"></a>            goog.net.BrowserChannel.Stat.TEST_STAGE_TWO_DATA_ONE);
<a name="line356"></a>        this.receivedIntermediateResult_ = true;
<a name="line357"></a>        this.firstTime_ = goog.now();
<a name="line358"></a>      } else {
<a name="line359"></a>        goog.net.BrowserChannel.notifyStatEvent(
<a name="line360"></a>            goog.net.BrowserChannel.Stat.TEST_STAGE_TWO_DATA_BOTH);
<a name="line361"></a>        this.firstTime_ = this.lastTime_ = goog.now();
<a name="line362"></a>        this.receivedIntermediateResult_ = false;
<a name="line363"></a>      }
<a name="line364"></a>    }
<a name="line365"></a>  }
<a name="line366"></a>};
<a name="line367"></a>
<a name="line368"></a>
<a name="line369"></a>/**
<a name="line370"></a> * Callback from ChannelRequest that indicates a request has completed.
<a name="line371"></a> *
<a name="line372"></a> * @param {goog.net.ChannelRequest} req  The request object.
<a name="line373"></a> */
<a name="line374"></a>goog.net.BrowserTestChannel.prototype.onRequestComplete =
<a name="line375"></a>    function(req) {
<a name="line376"></a>  this.lastStatusCode_ = this.request_.getLastStatusCode();
<a name="line377"></a>  if (!this.request_.getSuccess()) {
<a name="line378"></a>    this.channelDebug_.debug(
<a name="line379"></a>        &#39;TestConnection: request failed, in state &#39; + this.state_);
<a name="line380"></a>    if (this.state_ == goog.net.BrowserTestChannel.State_.INIT) {
<a name="line381"></a>      goog.net.BrowserChannel.notifyStatEvent(
<a name="line382"></a>          goog.net.BrowserChannel.Stat.TEST_STAGE_ONE_FAILED);
<a name="line383"></a>    } else if (this.state_ ==
<a name="line384"></a>               goog.net.BrowserTestChannel.State_.CONNECTION_TESTING) {
<a name="line385"></a>      goog.net.BrowserChannel.notifyStatEvent(
<a name="line386"></a>          goog.net.BrowserChannel.Stat.TEST_STAGE_TWO_FAILED);
<a name="line387"></a>    }
<a name="line388"></a>    this.channel_.testConnectionFailure(this,
<a name="line389"></a>        /** @type {goog.net.ChannelRequest.Error} */
<a name="line390"></a>        (this.request_.getLastError()));
<a name="line391"></a>    return;
<a name="line392"></a>  }
<a name="line393"></a>
<a name="line394"></a>  if (this.state_ == goog.net.BrowserTestChannel.State_.INIT) {
<a name="line395"></a>    this.channelDebug_.debug(
<a name="line396"></a>        &#39;TestConnection: request complete for initial check&#39;);
<a name="line397"></a>    if (this.blockedPrefix_) {
<a name="line398"></a>      this.state_ = goog.net.BrowserTestChannel.State_.CHECKING_BLOCKED;
<a name="line399"></a>      this.checkBlocked_();
<a name="line400"></a>    } else {
<a name="line401"></a>      this.state_ = goog.net.BrowserTestChannel.State_.CONNECTION_TESTING;
<a name="line402"></a>      this.connectStage2_();
<a name="line403"></a>    }
<a name="line404"></a>  } else if (this.state_ ==
<a name="line405"></a>             goog.net.BrowserTestChannel.State_.CONNECTION_TESTING) {
<a name="line406"></a>    this.channelDebug_.debug(&#39;TestConnection: request complete for stage 2&#39;);
<a name="line407"></a>    var goodConn = false;
<a name="line408"></a>
<a name="line409"></a>    if (goog.userAgent.IE) {
<a name="line410"></a>      // we always get Trident responses in separate calls to
<a name="line411"></a>      // onRequestData, so we have to check the time they came
<a name="line412"></a>      var ms = this.lastTime_ - this.firstTime_;
<a name="line413"></a>      if (ms &lt; 200) {
<a name="line414"></a>        // TODO: need to empirically verify that this number is OK
<a name="line415"></a>        // for slow computers
<a name="line416"></a>        goodConn = false;
<a name="line417"></a>      }
<a name="line418"></a>      else {
<a name="line419"></a>        goodConn = true;
<a name="line420"></a>      }
<a name="line421"></a>    } else {
<a name="line422"></a>      goodConn = this.receivedIntermediateResult_;
<a name="line423"></a>    }
<a name="line424"></a>
<a name="line425"></a>    if (goodConn) {
<a name="line426"></a>      this.channelDebug_.debug(
<a name="line427"></a>          &#39;Test connection succeeded; using streaming connection&#39;);
<a name="line428"></a>      goog.net.BrowserChannel.notifyStatEvent(
<a name="line429"></a>          goog.net.BrowserChannel.Stat.NOPROXY);
<a name="line430"></a>      this.channel_.testConnectionFinished(this, true);
<a name="line431"></a>    } else {
<a name="line432"></a>      this.channelDebug_.debug(
<a name="line433"></a>          &#39;Test connection failed; not using streaming&#39;);
<a name="line434"></a>      goog.net.BrowserChannel.notifyStatEvent(
<a name="line435"></a>          goog.net.BrowserChannel.Stat.PROXY);
<a name="line436"></a>      this.channel_.testConnectionFinished(this, false);
<a name="line437"></a>    }
<a name="line438"></a>  }
<a name="line439"></a>};
<a name="line440"></a>
<a name="line441"></a>/**
<a name="line442"></a> * Returns the last status code received for a request.
<a name="line443"></a> * @return {number} The last status code received for a request.
<a name="line444"></a> */
<a name="line445"></a>goog.net.BrowserTestChannel.prototype.getLastStatusCode = function() {
<a name="line446"></a>  return this.lastStatusCode_;
<a name="line447"></a>};
<a name="line448"></a>
<a name="line449"></a>
<a name="line450"></a>/**
<a name="line451"></a> * Gets whether this channel is currently active. This is used to determine the
<a name="line452"></a> * length of time to wait before retrying.
<a name="line453"></a> *
<a name="line454"></a> * @param {goog.net.BrowserChannel} browserChannel The browser channel.
<a name="line455"></a> * @return {boolean} Whether the channel is currently active.
<a name="line456"></a> */
<a name="line457"></a>goog.net.BrowserTestChannel.prototype.isActive =
<a name="line458"></a>    function(browserChannel) {
<a name="line459"></a>  return this.channel_.isActive();
<a name="line460"></a>};
</pre>


</body>
</html>
